// Connection class definition

#ifndef Connection_class
#define Connection_class

#include <sys/types.h>
#include <sys/socket.h>
#include <string>
#include <arpa/inet.h>
#include <iostream>
#include <fstream>

//Connection status's
enum { DEAD='d',IDLE='i',NEWBUSY='n', BUSY='b',FINISHED='f' };

class Connection
{
 public:
  Connection();
  Connection(std::string,int);
  virtual ~Connection();

  void init(std::string,int);
  void setidle(); //This connection is waiting for a job (default)
  void setnewbusy(int,bool); //This connection is doing a job
  void setbusy(); //Change from newly busy to actually running - busy
  void setfinished();
  void setuname(std::string);
  void kill(); //This connection was lost and is going to be deleted!

  std::string get_signature();

  void print(std::ofstream*);
  void print_scr();

  void lock();
  void unlock();
  
  std::string get_ip();
  char get_status();
  bool get_leader();
  int get_group();
  std::string get_uname();

  void setpubkeyfile(const char*);
  const char* getpubkeyfile();
  const char* getshortpubkeyfile();

  pthread_mutex_t sendmux;

 private:

  pthread_mutex_t Mux;
  std::string IP;
  int Port;
  int Group;
  bool Leader;
  char Status;
  const char* pubkeyfile;
  std::string Username;
};

#endif
